package com.fjeld.client.gui.screens;

import com.fjeld.swingx.JTransparentPanel;
import com.fjeld.swingx.JTransparentScrollPane;
import com.fjeld.swingx.JContentRenderingPanel;
import com.fjeld.client.gui.control.navigation.TreeNavigationPanel;
import com.fjeld.client.gui.control.navigation.SideBar;

import javax.swing.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: fjelds
 * Date: Mar 17, 2010
 * Time: 11:34:23 PM
 *
 *
 */
public class ProductionLineView extends JContentRenderingPanel implements PropertyChangeListener
{
    public static ProductionLineView PRODUCTION_LINE_VIEW = new ProductionLineView();
    private TreeNavigationPanel activeSideComponent;
    private JComponent activeComponent  = null;
    private JPanel holderPanel = new JTransparentPanel();

    private ProductionLineView()
    {
        activeSideComponent = new TreeNavigationPanel(this);

        JScrollPane scrollPane = new JTransparentScrollPane(holderPanel);
        this.add(scrollPane, BorderLayout.CENTER);

        addPropertyChangeListener(this);
    }

    public void propertyChange(PropertyChangeEvent propertyChangeEvent)
    {
        SideBar.getINSTANCE().displayContentPanel(activeSideComponent);
    }

    public void displayContent(JComponent contentPanel)
    {
        if (activeComponent != null)
            holderPanel.remove(activeComponent);

        activeComponent = contentPanel;
        holderPanel.add(activeComponent, BorderLayout.NORTH);
        revalidate();
        repaint();
    }
}
